package com.hd.trans.network.bean.textToVoice

import android.util.ArrayMap
import com.hd.trans.network.ParamUtils
import com.hd.trans.network.bean.UserInfoBean
import okhttp3.RequestBody

/**
 * AI陪练：创建文字转语音任务请求数据
 */
data class Text2VoiceRequest(
    val text_url: String? = null,//文本链接
    val text: String? = null,//文本内容,短文本选用,链接与内容二选一
    val lang: String? = null,//默认值:zh-CN,lang可选值参考同一路径下的：lang.txt
    val pitch: Float = 1f,//音调,范围: 0.5~2,默认值:1
    val volume: Float = 1f,//音量,范围:0~1,默认值:1
    val rate: Float = 0.5f,//语速,范围:0~1,默认值0.5
    val type: String? = null,//可以用值（类型）： aac  默认值 mp3、m4a、wav、flac
){
    fun makeRequestBody(userinfoBean: UserInfoBean?): RequestBody {
        val params = ParamUtils.createText2VoiceParams(ArrayMap<String, Any>().apply {
            text_url?.let {
                put("text_url", it)
            }
            text?.let {
                if(it.isNotEmpty()){
                    remove("text_url")
                    put("text", it)
                }
            }
            lang?.let {
                put("lang", it)
            }
            type?.let {
                put("type", it)
            }

            val mPitch = if(pitch in 0.5..2.0){
                pitch
            }else{
                1.0f
            }
            put("pitch", mPitch)
            put("volume", volume)
            put("rate", rate)
        }, userinfoBean)
        return params
    }
}

